package com.android.flowoflife;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.GridView;

import com.android.flowoflife.activities.CreateFlow;
import com.android.flowoflife.activities.Profiler;
import com.android.flowoflife.activities.ViewFlow;
import com.android.flowoflife.adapters.TestAdapter;

public class Main extends Activity {
	private static final String TAG = "Main_activity";

	@Override
	protected Dialog onCreateDialog(int id) {
		return new AlertDialog.Builder(Main.this).setTitle(
				R.string.start_menu_dialog).setItems(
				R.array.start_menu_dialog_items,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						Intent intent = new Intent();
						switch (which) {
						case 0:
							//Log.v(TAG, "Create a flow");
							Log.v(TAG, "Starting the shooting service!");
							//intent.setClass(Main.this, CreateFlow.class);
							//intent.setClass(Main.this, PhotoService.class);
							//intent.putExtra(IFlowOfLifeConstants.STOP_SERVICE, false);
							//startService(intent);
							Alarms.scheduleNextPhotoshoot(Main.this);
							break;
						case 1:
							//Log.v(TAG, "View flows");
							Log.v(TAG, "Stopping the service");
							//intent.setClass(Main.this, ViewFlow.class);
							//intent.setClass(Main.this, PhotoService.class);
							//intent.putExtra(IFlowOfLifeConstants.STOP_SERVICE, true);
							//startService(intent);
							Alarms.cancel(Main.this);
							break;
						case 2:
							Log.v(TAG, "Profile Setting");
							intent.setClass(Main.this, Profiler.class);
							break;
						default:
							break;
						}
						//startActivity(intent);
//						finish();
					}
				}).create();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.start_dialog);
		showDialog(0);
		
		GridView gridView = (GridView) findViewById(R.id.gridView);
		gridView.setAdapter(new TestAdapter(this));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuItem item = menu.add(0, IFlowOfLifeConstants.MENU_CREATE_FLOW, 0, "New flow");
		item.setIcon(R.drawable.multimedia_icon);
		item = menu.add(0, IFlowOfLifeConstants.MENU_VIEW_FLOW, 0, "View flows");
		item.setIcon(R.drawable.home_icon);
		item = menu.add(0, IFlowOfLifeConstants.MENU_PROFILER, 0, "Profiler");
		item.setIcon(R.drawable.icon);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Intent intent = new Intent();
		switch(item.getItemId()){
		case IFlowOfLifeConstants.MENU_CREATE_FLOW:
			Log.v(TAG, "Create a flow from menu");
			intent.setClass(Main.this, CreateFlow.class);
			break;
		case IFlowOfLifeConstants.MENU_VIEW_FLOW:
			Log.v(TAG, "View flows from menu");
			intent.setClass(Main.this, ViewFlow.class);
			break;
		case IFlowOfLifeConstants.MENU_PROFILER:
			Log.v(TAG, "Profile flows from menu");
			intent.setClass(Main.this, Profiler.class);
			break;
		default:
			break;
		}
		startActivity(intent);
		return true;
	}
	
	
}